
package com.mephi.util;


/**
 * An enum class which represents the sort of pieces with its values
 * @author mephisto
 * 2011-06-13
 */
public enum PieceSort 
{
	PAWN(1.0f), KNIGHT(3.0f), BISHOP(3.1f), ROOK(5.0f), QUEEN(8.0f), KING(64.0f);
	
	
	/**
	 * 
	 * if s equals to empty string return {@code PieceSort.PAWN} 
	 * if s equals to 'N' return {@code PieceSort.KNIGHT} 
	 * if s equals to 'B' return {@code PieceSort.BISHOP} 
	 * if s equals to 'Q' return {@code PieceSort.QUEEN} 
	 * if s equals to 'K' return {@code PieceSort.KING} 
	 * if s equals to 'R' return {@code PieceSort.ROOK} 
	 * in the other case returns {@code null}
	 * 
	 * @param s the letter to set,
	 * 			english is the default language 
	 * @return PieceSort indicated by the letter
	 */
	public static PieceSort valueOfLetter(String s)
	{
		s = s.trim();
		if (s.equals(Constants.EMPTY_STRING))
			return PieceSort.PAWN;
		else if  (s.equals(Constants.N_CAPITAL_LETTER))
			return PieceSort.KNIGHT;
		else if  (s.equals(Constants.B_CAPITAL_LETTER))
			return PieceSort.BISHOP;
		else if  (s.equals(Constants.Q_CAPITAL_LETTER))
			return PieceSort.QUEEN;
		else if  (s.equals(Constants.K_CAPITAL_LETTER))
			return PieceSort.KING;
		else if  (s.equals(Constants.R_CAPITAL_LETTER))
			return PieceSort.ROOK;
		return null;
	}
		
	/**
	 * 
	 * @return the value of the PieceSort
	 */
	public float getValue()
	{
	   return value;
	}
	
	/**
	 * 
	 * @return the first letter of chess notation in english 
	 * 		   or empty string if it is pawn
	 */
	public String getAsLetter()
	{
		if (this.equals(PieceSort.PAWN))
			return Constants.EMPTY_STRING;
		return this.toString().substring(0, 1);
	}

	private PieceSort(float value) 
	{
	   this.value = value;
	}
	
	
	private float value;
}
